<?php
/*
	generate single quoted string and escape special characters
*/
function procStrField($str){
	return "'".addslashes($str)."'";
}

/*
	print out array
*/
function showArr($arr){
	print('<pre>');
	print_r($arr);
	print('</pre>');
}

/*
	check login flag
*/
function isLogin(){
	if (isset($_SESSION['userinfo'])){
		return true;
	}
	else {
		return false;
	}
}

/*
	page navigation
*/
function redirect($url){
	print("<script language='javascript'>location='".$url."'</script>");
}

/*
	initiate login header section
*/
function initHeader(){
	if (isset($_SESSION['userinfo'])){
		// table begin
		print('<table align=right>');
		print('<tr>');
		
		// table content
		print('<td>');
		print('<a href=\'login.php?action=logout\'><font color=#ffffff>Logout&nbsp;&nbsp;&nbsp;</font></a>');
		print('</td>');
		
		print('<td>');
		print('<a href=\'profile.php?action=load\'><font color=#ffffff>&nbsp;&nbsp;&nbsp;Profile&nbsp;&nbsp;&nbsp;</font></a>');
		print('</td>');

		print('<td>');
		print('<a href=\'cart.php\'><font color=#ffffff>&nbsp;&nbsp;&nbsp;Shopping Cart</font></a>');
		print('</td>');

		// table end
		print('</tr>');
		print('</table>');
	}
	else {
		// table begin
		print('<table align=right>');
		print('<tr>');
		
		// table content
		print('<td>');
		print('<a href=\'login.php\'><font color=#ffffff>Login&nbsp;&nbsp;&nbsp;</font></a>');
		print('</td>');

		// table end
		print('</tr>');
		print('</table>');
	}
}

/*
	add zero to the end of money value if it has only one digit after decimal
	parameter must be decimal type
*/
function mny_format($val){
	$parts = split('\.',$val);
	
	if (count($parts) == 1){
		return $val.'.00';
	}
	else {
		if (strlen($parts[1]) == 0){
			return $val.'00';
		}
		else if (strlen($parts[1]) == 1){
			return $val.'0';
		}
		else {
			return $val;
		}
	}
}
?>